﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;


namespace nadModel
{
    [Serializable]
    public class TextFileLogger : Logger
    {
        private string filename;
        public TextFileLogger(string filename, LogLevel level)
        {
            this.filename = filename;
            base.LogLevel = level;
        }
        public override void Log(string msg)
        {
            this.Log(msg, LogLevel.INFO);
        }

        public override void Log(string msg, LogLevel lvl)
        {
            if ((this.filename != null) && (lvl >= base.LogLevel))
            {
                string str2;
                DateTime now = DateTime.Now;
                string path = this.filename + "-" + string.Format("{0:0000}{1:00}{2:00}", now.Year, now.Month, now.Day) + ".log";
                Monitor.Enter(str2 = this.filename);
                try
                {
                    StreamWriter writer = File.AppendText(path);
                    writer.WriteLine(msg);
                    writer.Flush();
                    writer.Close();
                }
                catch (Exception)
                {
                }
                finally
                {
                    Monitor.Exit(str2);
                }
            }
        }
    }
}
